/*
 * Copyright (c) Zhongkehonglue Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Implementation of functions related to the DMC DEV module.
 * Author: wangchunyang
 * Create: 2025-05-23
 */

 #include "handleStr.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 namespace DlnaDmc {

std::string ReplaceAll(std::string resource_str, std::string sub_str, std::string new_str)
{
    size_t pos = resource_str.find(sub_str);
    while (pos != std::string::npos) {
        resource_str.replace(pos, sub_str.length(), new_str); 
        pos = resource_str.find(sub_str, pos + new_str.length());
    }
    return resource_str;
}

std::string ReplaceUrl(std::string resource_str)
{
    // CLOGI("Start Escape URL");
    if (resource_str.find("&amp;") != std::string::npos) {
        return resource_str;
    }
    std::string dst_str = ReplaceAll(resource_str, "&", "&amp;");
    dst_str = ReplaceAll(dst_str, "<", "&lt;");
    dst_str = ReplaceAll(dst_str, ">", "&gt;");
    dst_str = ReplaceAll(dst_str, "\"", "&quot;");
    dst_str = ReplaceAll(dst_str, "'", "&apos;");
    return dst_str;
}
}
